<template>
  <div>
    <div v-if="!pushStatus">
    <el-row style="margin-bottom:10px">
      <el-col :span="8" >
        <h4 style="margin:0">
          <span>预约列表</span>
          <!-- <el-button  type="success" class="addBtn" @click="addUserFun"><i class="el-icon-plus"></i>账号</el-button>           -->
        </h4>
      </el-col>
      <el-col :span="16" style="text-align:right">
        <el-input v-model="sheachValue" style="width:300px" placeholder="输入搜索内容"></el-input>
          <el-button type="primary" @click="seachWordFun">搜索</el-button>
      </el-col>
    </el-row>
   
    <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55"></el-table-column>-->
      <el-table-column prop="ID" label="序号" width="60">
         <template slot-scope="scope">{{scope.$index+1}}</template>
      </el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="tel" label="手机"></el-table-column>
      <el-table-column prop="applicant_id" label="id"></el-table-column>
      <el-table-column prop="time" label="预约时间">
        <template slot-scope="scope">
          {{timeFun(scope.row.time)}}
        </template>
      </el-table-column>
      <el-table-column prop="hospital_name" label="医院"></el-table-column>
      <el-table-column prop="age" label="年龄">
        <!-- <template slot-scope="scope">
          {{ageFun(scope.row.age)}}
        </template> -->

       
      </el-table-column>
      <el-table-column prop="server_tag" label="咨询内容"></el-table-column>
      <el-table-column prop="type" label="类别">
        <template  slot-scope="scope">
          <span style="color:#67c23a" v-if="scope.row.type==1">商家预约</span>
          <span v-else-if="scope.row.type==2">活动预约</span>
          <span v-else>商品预约</span>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注"></el-table-column>
      <el-table-column prop="tui" label="状态">
        <template  slot-scope="scope">
          <span v-if="scope.row.status==0">未到店</span>
          <span style="color:#67c23a" v-else-if="scope.row.status==1">已到店</span>
          <span style="color:red" v-else-if="scope.row.status==2">取消预约</span>
          <span style="color:#409EFF" v-else-if="scope.row.status==3">已过期</span>
        </template>
      </el-table-column>
      <el-table-column width="80" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button class="addBtn" type="primary" @click="seachFun(scope.row)">查看</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
   
    <div v-if="pushStatus">
       <Seach-reserve @colseFun="colseFun" :editData="editVal"></Seach-reserve>
    </div>
  </div>
</template>

<script>
  import SeachReserve from './ResItem/SeachReserve'
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        editVal:'',
        sheachValue:'',
        pushStatus:false,
        dialogVisible:false,
        dataPush:'',
        total:0,
        currentPage4: 1,//分野  
        page:1,
        pageSize:10,
        tableData: []
      }
    },
    components:{
      SeachReserve
    },
    created(){
      this.getlist()
    },
    methods: {
      getlist(){
        const obj = {
          "pageIndex":this.page,
          "pageSize":this.pageSize
        };
        if (this.sheachValue) {
          obj.keyword = this.sheachValue
        };
        Http.getReservelList(obj)
        .then( res => {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total;
           this.pushStatus = false
        })
        .catch( error => {
        })
      },
      getdata (evt) {
      },
      timeFun(val) {
        return getTime(val)
      },
      ageFun(val) {
        const newo = new Date();
        const newYear = newo.getFullYear();
        const now =  new Date(val)
        const year = now.getFullYear();
        return newYear - year
      },
      seachWordFun() {
        this.getlist()
      },
      colseFun(){
        this.pushStatus = false;
        this.getlist()
      },
      //添加用户
      addUserFun() {
        this.editVal = '';
        this.pushStatus = true;
      },
      seachFun(row){
        this.pushStatus = true;
        this.editVal = row;
      },
      //禁用 账号
      disabelFun(row){
        Http.disableAdmin(row)
        .then( res => {
          if ( res.data.code == 200 ){
            this.$message.success(`禁用成功`)
            this.getlist()
          } else if (res.data.code == -1003) {
              this.$message.error(`token过期，请重新登录`)
              this.$router.push('/')
          } else {
            this.$message.error('账号添加失败')
          }
        })
      },
      //选择 推荐
      handleSelectionChange() {
        
      },
         //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getlist()
      },
    }
  }
</script>
<style  scoped>
.box{
  border-bottom:1px solid red;
}
    .test{
        border:1px solid #ccc;
    }
    .drag-item{
        width: 200px;
        height: 50px;
        line-height: 50px;
        margin: auto;
        position: relative;
        
        background: #ddd;
        margin:20px 5px;
    }
    .ghostClass{
        opacity: 1;
    }
    .bottom{
        width: 200px;
        height: 50px;
        position: relative;
        background: blue;
        top:2px;
        left: 2px;
        transition: all .5s linear;
    }
</style>
